package com.example.medicalretrieval.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.medicalretrieval.R;
import com.example.medicalretrieval.pojo.PdfItem;

import java.util.List;

public class PDFItemAdapter extends BaseAdapter {
    private final Context mContext;
    private List<PdfItem> mPdfItemList;
    public PDFItemAdapter(Context context, List<PdfItem> pdfItemList){
        this.mContext = context;
        this.mPdfItemList = pdfItemList;
    }
    @Override
    public int getCount() {
        return mPdfItemList.size();
    }

    @Override
    public Object getItem(int position) {
        return mPdfItemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_pdf,null);
            holder = new ViewHolder();
            holder.tv_title = convertView.findViewById(R.id.tv_title);
            holder.tv_abstract = convertView.findViewById(R.id.tv_abstract);
            holder.tv_author = convertView.findViewById(R.id.tv_author);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        PdfItem pdfItem = mPdfItemList.get(position);

        holder.tv_title.setText(pdfItem.getTitle());
        holder.tv_author.setText(pdfItem.getAuthors());
        holder.tv_abstract.setText(pdfItem.getAbstractContent());

        return convertView;
    }

    public final class ViewHolder{
        public TextView tv_title;
        public TextView tv_abstract;
        public TextView tv_author;
    }

}
